<?php
    class DisciplinaModel extends CI_Model{
     
        public function get($id){
            $this->db->where('id',$id);
            return $this->db->get('disciplina')->row();
        }
        
        public function listar(){
            $this->db->order_by('disciplina');
            $this->db->join('curso','disciplina.curso_id = curso.id');
            $this->db->select('disciplina.id, disciplina, creditos, curso.curso');
            return $this->db->get('disciplina')->result();
        }
        
        public function cadastrar($dados){
            return $this->db->insert('disciplina', $dados);
        }
        
        public function editar($dados){
            $this->db->where('id', $dados['id']);
            return $this->db->update('disciplina',$dados);
        }
        
        public function excluir($id){
            $this->db->where('id', $id);
            return $this->db->delete('disciplina');
        }
        
        public function drop(){
            $this->db->select('id,disciplina');
            $this->db->order_by('disciplina');
            $values = $this->db->get('disciplina')->result_array();
            
            $options = array();
            $options[''] = '- Selecione -';
            foreach($values as $value){
                $options[$value['id']] = $value['disciplina'];
            }
            return $options;
        }
        
    }
?>
